import HttpRequest from './request'

/**
 * 获取Banner接口
 */
function getBanner() {
  return HttpRequest.get({
    url: '/banner/json',
    checkResultCode: false
  })
}

/**
 * 获取首页接口
 * @param index
 */
function getHomeList(index) {
  return HttpRequest.get({url: '/article/list/' + index + '/json'})
}

/**
 * 获取系统架构数据
 */
function getSystem() {
  return HttpRequest.get({url: '/tree/json'});
}

/**
 * 获取微信公众号Tab数据
 */
function getWeChatTab() {
  return HttpRequest.get({url: '/wxarticle/chapters/json'});
}

/**
 * 获取公众号的历史文章列表
 * @param id
 * @param index
 */
function getChatHistory(id, index) {
  return HttpRequest.get({url: '/wxarticle/list/' + id + '/' + index + '/json'})
}

/**
 * 获取导航数据
 */
function getSite() {
  return HttpRequest.get({url: '/navi/json'});
}

/**
 * 登录接口
 * @param phone
 * @param password
 */
function login(phone, password) {
  return HttpRequest.post({
      url: '/user/login',
      params: {'username': phone, 'password': password}
  })
}

/**
 * 获取项目分类
 */
function getProjectType() {
  return HttpRequest.get({url: '/project/tree/json'})
}

/**
 * 获取项目列表
 */
function getProjectList(id, index) {
  return HttpRequest.get({url: '/project/list/' + index + '/json?cid=' + id})
}

/**
 * 获取收藏列表
 * @param pageIndex
 */
function getCollectList(pageIndex) {
  return HttpRequest.get({url: '/lg/collect/list/' + pageIndex + '/json'})
}

/**
 * 收藏站内文章
 * @param id
 */
function addFavorite(id) {
  return HttpRequest.post({
      url: '/lg/collect/' + id + '/json',
      checkLoginState: true,
      needJumpToLogin: true,
      showLoading: true
  })
}

export default {
  getBanner,
  getHomeList,
  getSystem,
  getWeChatTab,
  getChatHistory,
  getSite,
  login,
  getProjectType,
  getProjectList,
  getCollectList,
  addFavorite,
}
